package net.zjitc.atest.service.impl;




import net.zjitc.atest.mapper.AdminMapper;
import net.zjitc.atest.pojo.Admin;
import net.zjitc.atest.service.AdminService;
import net.zjitc.atest.util.MD5SaltUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin findAdmin(String username, String password) throws IOException {
        Admin admin = adminMapper.findAdmin(username);
        if (admin==null){
            return null;
        } else {
            String PSW = MD5SaltUtil.hashPasswordWithSalt(password, "ItCast");
            if (PSW.equals(admin.getPassword())){
                return admin;
            }
            return null;
        }

    }

}
